package mvc.unti;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import mvc.form.BaseForm;

public class FullBean {

	public static BaseForm full(String className, HttpServletRequest request) {
		BaseForm baseForm = null;
		try {
			Class<?> clazz = Class.forName(className);
			baseForm = (BaseForm) clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				field.setAccessible(true);
				field.set(baseForm, request.getParameter(field.getName()));
				field.setAccessible(false);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return baseForm;
	}
}
